<template>
  <el-dialog title="需求审批" :visible.sync="isOpen" width="600px" append-to-body>
    <el-form ref="form" :model="auditForm" :rules="rules" label-width="120px">
      <el-form-item label="审批结论" prop="check_status">
        <el-select
          v-model="auditForm.check_status"
          placeholder="请选择审批结论"
          clearable
          :style="{ width: '100%' }"
        >
          <el-option
            v-for="(item, index) in auditOptions"
            :key="index"
            :label="item.label"
            :value="item.value"
            :disabled="item.disabled"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="审批意见" prop="remark">
        <el-input
          v-model="auditForm.remark"
          type="textarea"
          placeholder="请输入审批意见"
          :autosize="{ minRows: 3, maxRows: 6 }"
          :style="{ width: '100%' }"
        />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="submitForm">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { approveOperation } from '@/api/requirement'
export default {
  props: {
    requireId: {
      type: String,
      default: () => {}
    }
  },
  data() {
    return {
      isOpen: false,
      auditForm: {
        check_status: '',
        remark: ''
      },
      auditOptions: [
        {
          label: '通过',
          value: 1
        },
        {
          label: '拒绝',
          value: 2
        },
      ],
      // 弹框
      rules: {
        check_status: [
          { required: true, message: '请选择评估结论', trigger: 'blur' }
        ],
        remark: []
      }
    }
  },
  // 生命周期 - 创建完成（访问当前this实例）
  created() {},
  methods: {
    // 表单重置
    reset() {
      this.auditForm = {
        check_status: '',
        remark: ''
      }
      this.resetForm('form')
    },
    // 取消按钮
    close() {
      this.isOpen = false
      this.reset()
    },
    // 打开弹框
    open() {
      this.isOpen = true
    },
    /** 提交按钮 */
    submitForm() {
      const that = this
      that.auditForm.id = this.requireId
      this.$refs['form'].validate((valid) => {
        if (valid) {
          approveOperation(that.auditForm).then(res => {
            if (res.code === 200) {
              that.$emit('auditSuccess')
              that.isOpen = false
            }
          })
        }
      })
    }
  }
}
</script>
<style scoped>
/* @import url(); 引入css类 */
</style>
